<template>
	<view class="page page-fill">
		 <form @submit="submitFormChangeSex">
		 	    <radio-group @change="changeSex" class="radio-group">
		 	    	<label class="radio">
		 	    		<radio value="1" name="sex" :checked="sex==1"/><text>男</text>
				    </label>
					<label class="radio">
					   <radio value="0" name="sex" :checked="sex==0"/><text>女</text>
				    </label>
			  </radio-group>
		 	  </picker-view>
		   <button class="btn" form-type="submit" type="primary">提交</button>
		 </form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				sex:-1,
				userInfo:{}
			}
		},
		onLoad(){
		  var userInfo = uni.getStorageSync("globalInfo");
		      this.userInfo = userInfo;
		      this.sex = userInfo.sex;
		},
		methods: {
			changeSex(e){
				var sex = e.detail.value;
				    this.sex = sex;
			},
			submitFormChangeSex(){
				uni.showLoading();
				  uni.request({
				  	  url:this.serverUrl + '/user/modifyUserinfo/?qq=3316368400',
					  header:{
					  	"headerUserId":this.userInfo.id,
					  	"headerUserToken":this.userInfo.userUniqueToken
					  },
					  data:{
					  	"userId": this.userInfo.id,
					  	"sex":this.sex
					  },
					  method:'POST',
					  success:(res)=>{
						  console.log(res);
						  if(res.data.status === 200){
							 uni.setStorageSync('globalInfo',res.data.data)
							  uni.navigateBack({
							  	delta:1
							  })
						  }
					 },
					 complete:()=>{
						 uni.hideLoading();
					 }
			});
			}
			}
		
	}
	
	

</script>

<style>
  .radio-group{
	  display: flex;
	  flex-direction: column;
	  margin-top: 40upx;
	  padding: 0 40upx;
  }
  .radio{
	  height: 100upx;
  }
  .btn{
  	 width: 90%;
  	 margin-top: 40upx;
  }
</style>
